home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / imagine / extras / tools / isl3_0b6 / samples / islappnd.c < prev    next >
C/C++ Source or Header  |  1995-01-30  |  10KB  |  413 lines

  1. /*
  2. islappnd.c - append two stages - Copyright (c) 1995 John T. Grieggs
  3.  
  4. This program expects two Imagine 3.0 stages, produced by ISL, and makes
  5. a third stage containing both.  This is not entirely trivial, and you
  6. may get wierd effects.  Think about what you're doing here.  What do you
  7. expect multiple SIZE chunks on GLOBALS to do?  If things don't work quite
  8. the way you expect, your resulting stage may require tweaking.  I highly
  9. recommend scoping out each stage before combining them, and making sure
  10. all the paths are what you intend.
  11.  
  12. islappnd.c is pretty darned brute force, and riddled with assumptions.  If
  13. the format isn't just what ISL produces, or if you use chunks I didn't think
  14. you'd use, it'll break.  That's why you get the source.  :-)
  15.  
  16. It's actually not a bad example of ISL programming, tho.  Feel free to
  17. grab the unregistered version of ISL from ftp.netcom.com, in the
  18. pub/gr/grieggs/ISL directory.  Be warned that the unregistered version
  19. will not handle EFFECT clauses.
  20.  
  21. I'll put compiled versions of this program for the Amiga and the PC
  22. in the same directory when I get around to it.
  23.  
  24. You are welcome to hack this to your hearts content, but may not sell it or
  25. bundle it with any product without specific permission from me.  You may,
  26. however, freely distribute the original source to BBSes, ftp sites, and
  27. online services.  You may distribute modified versions as long as my
  28. comments remain intact and you clearly comment your modifications.
  29.  
  30. Cheapo manual:
  31.  
  32.     Copy staging file from first project to staging.1
  33.     Copy staging file from second project to staging.2
  34.  
  35.     destage staging.1 stage.1
  36.     destage staging.2 stage.2
  37.     islappnd stage.1 stage.2 stage.3
  38.     restage stage.3 staging.3
  39.  
  40.     If no errors, copy staging.3 to new project directory
  41.  
  42. Happy rendering!
  43.  
  44. grieggs@netcom.com
  45.  
  46. */
  47.  
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include <string.h>
  51.  
  52. #define MAXBUF 200
  53.  
  54. FILE *fin1, *fin2, *fout;
  55. char inbuf[MAXBUF], outbuf[MAXBUF];
  56. char inbuf1[MAXBUF], inbuf2[MAXBUF];
  57. char *p;
  58. int start, finish;
  59. int max1, max2;
  60.  
  61. main(int argc, char *argv[])
  62. {
  63.     /* check args */
  64.     if (argc != 4) {
  65.         fprintf(stderr, "Usage: islappnd instage1 instage2 outstage\n");
  66.         exit(1);
  67.     }
  68.  
  69.     /* open files */
  70.     fin1 = fopen(argv[1], "r");
  71.     if (fin1 == NULL) {
  72.         fprintf(stderr, "Unable to open %s for input\n", argv[1]);
  73.         exit(1);
  74.     }
  75.     fin2 = fopen(argv[2], "r");
  76.     if (fin2 == NULL) {
  77.         fprintf(stderr, "Unable to open %s for input\n", argv[2]);
  78.         exit(1);
  79.     }
  80.     fout = fopen(argv[3], "w");
  81.     if (fout == NULL) {
  82.         fprintf(stderr, "Unable to open %s for output\n", argv[3]);
  83.         exit(1);
  84.     }
  85.  
  86.     /* get maxframes from first file */
  87.     fgets(inbuf, MAXBUF, fin1);
  88.     fgets(inbuf, MAXBUF, fin1);
  89.     if (!strncmp(inbuf, "MAXFRAMES", strlen("MAXFRAMES"))) {
  90.         p = strstr(inbuf, " ");
  91.         p++;
  92.         max1 = atoi(p);
  93.     }
  94.     fgets(inbuf, MAXBUF, fin1);
  95.     fgets(inbuf, MAXBUF, fin1);
  96.  
  97.     /* get maxframes from second file */
  98.     fgets(inbuf, MAXBUF, fin2);
  99.     fgets(inbuf, MAXBUF, fin2);
  100.     if (!strncmp(inbuf, "MAXFRAMES", strlen("MAXFRAMES"))) {
  101.         p = strstr(inbuf, " ");
  102.         p++;
  103.         max2 = atoi(p);
  104.     }
  105.     fgets(inbuf, MAXBUF, fin2);
  106.     fgets(inbuf, MAXBUF, fin2);
  107.  
  108.     /* write header lines, forcing LOOP off */
  109.     fprintf(fout, "STAGE\nMAXFRAMES %d\nLOOP 0\n\n", max1 + max2);
  110.  
  111.     /* process CAMERAs - this is where it gets gnarly */
  112.     fgets(inbuf, MAXBUF, fin1);
  113.     /* make sure you have CAMERA line from first file */
  114.     if (strncmp(inbuf, "CAMERA", strlen("CAMERA"))) {
  115.         fprintf(stderr, "bad CAMERA\n");
  116.         exit(1);
  117.     }
  118.     fputs(inbuf, fout);
  119.     /* write it - this means all CAMERAs will share a LAYER */
  120.     fgets(inbuf, MAXBUF, fin2);
  121.     /* make sure you have CAMERA line from second file */
  122.     if (strncmp(inbuf, "CAMERA", strlen("CAMERA"))) {
  123.         fprintf(stderr, "bad CAMERA\n");
  124.         exit(1);
  125.     }
  126.  
  127.     /* We're handling POSITION, ALIGN, and SIZE clauses from each file
  128.        here, but not ASSOCs or EFFECTs.  Yeah, yeah, it's tacky.  Feel free
  129.        to write your own.  :-)  EFFECTs would be particularly nasty, as
  130.        they can span multiple lines.  Still, this will handle any stage
  131.        I've seen to date - just not every stage allowed by the grammar. */
  132.  
  133.     /* prime the pump */
  134.     fgets(inbuf1, MAXBUF, fin1);
  135.     fgets(inbuf2, MAXBUF, fin2);
  136.  
  137.     /* POSITION clauses */
  138.     for (;;) {
  139.         if (strncmp(inbuf1, "POSITION", strlen("POSITION")))
  140.             break;
  141.         fputs(inbuf1, fout);
  142.         fgets(inbuf1, MAXBUF, fin1);
  143.     }
  144.     for (;;) {
  145.         if (strncmp(inbuf2, "POSITION", strlen("POSITION")))
  146.             break;
  147.         /* find key string */
  148.         p = strstr(inbuf2, " FRAMES ");
  149.         if (p == NULL) {
  150.             fputs(inbuf2, fout);
  151.             continue;
  152.         }
  153.         p += strlen(" FRAMES ");
  154.         /* get start frame */
  155.         start = atoi(p);
  156.         /* write first part of line */
  157.         *p++ = '\0';
  158.         fputs(inbuf2, fout);
  159.         /* write shifted start frame */
  160.         fprintf(fout, "%d ", start + max1);
  161.         /* get end frame */
  162.         p = strchr(p, ' ');
  163.         p++;
  164.         finish = atoi(p);
  165.         /* write shifted end frame */
  166.         fprintf(fout, "%d ", finish + max1);
  167.         /* write rest of line */
  168.         p = strchr(p, ' ');
  169.         p++;
  170.         fputs(p, fout);
  171.         fgets(inbuf2, MAXBUF, fin2);
  172.     }
  173.  
  174.     /* ALIGN clauses */
  175.     for (;;) {
  176.         if (strncmp(inbuf1, "ALIGN", strlen("ALIGN")))
  177.             break;
  178.         fputs(inbuf1, fout);
  179.         fgets(inbuf1, MAXBUF, fin1);
  180.     }
  181.     for (;;) {
  182.         if (strncmp(inbuf2, "ALIGN", strlen("ALIGN")))
  183.             break;
  184.         /* find key string */
  185.         p = strstr(inbuf2, " FRAMES ");
  186.         if (p == NULL) {
  187.             fputs(inbuf2, fout);
  188.             continue;
  189.         }
  190.         p += strlen(" FRAMES ");
  191.         /* get start frame */
  192.         start = atoi(p);
  193.         /* write first part of line */
  194.         *p++ = '\0';
  195.         fputs(inbuf2, fout);
  196.         /* write shifted start frame */
  197.         fprintf(fout, "%d ", start + max1);
  198.         /* get end frame */
  199.         p = strchr(p, ' ');
  200.         p++;
  201.         finish = atoi(p);
  202.         /* write shifted end frame */
  203.         fprintf(fout, "%d ", finish + max1);
  204.         /* write rest of line */
  205.         p = strchr(p, ' ');
  206.         p++;
  207.         fputs(p, fout);
  208.         fgets(inbuf2, MAXBUF, fin2);
  209.     }
  210.  
  211.     /* SIZE clauses */
  212.     for (;;) {
  213.         if (strncmp(inbuf1, "SIZE", strlen("SIZE")))
  214.             break;
  215.         fputs(inbuf1, fout);
  216.         fgets(inbuf1, MAXBUF, fin1);
  217.     }
  218.     for (;;) {
  219.         if (strncmp(inbuf2, "SIZE", strlen("SIZE")))
  220.             break;
  221.         /* find key string */
  222.         p = strstr(inbuf2, " FRAMES ");
  223.         if (p == NULL) {
  224.             fputs(inbuf2, fout);
  225.             continue;
  226.         }
  227.         p += strlen(" FRAMES ");
  228.         /* get start frame */
  229.         start = atoi(p);
  230.         /* write first part of line */
  231.         *p++ = '\0';
  232.         fputs(inbuf2, fout);
  233.         /* write shifted start frame */
  234.         fprintf(fout, "%d ", start + max1);
  235.         /* get end frame */
  236.         p = strchr(p, ' ');
  237.         p++;
  238.         finish = atoi(p);
  239.         /* write shifted end frame */
  240.         fprintf(fout, "%d ", finish + max1);
  241.         /* write rest of line */
  242.         p = strchr(p, ' ');
  243.         p++;
  244.         fputs(p, fout);
  245.         fgets(inbuf2, MAXBUF, fin2);
  246.     }
  247.  
  248.     fprintf(fout, "\n");
  249.  
  250.     /* process GLOBALSs */
  251.     fgets(inbuf, MAXBUF, fin1);
  252.     /* make sure you have GLOBALS line from first file */
  253.     if (strncmp(inbuf, "GLOBALS", strlen("GLOBALS"))) {
  254.         fprintf(stderr, "bad GLOBALS\n");
  255.         exit(1);
  256.     }
  257.     fputs(inbuf, fout);
  258.     /* write it - this means all GLOBALSs will share a LAYER */
  259.     fgets(inbuf, MAXBUF, fin2);
  260.     /* make sure you have GLOBALS line from second file */
  261.     if (strncmp(inbuf, "GLOBALS", strlen("GLOBALS"))) {
  262.         fprintf(stderr, "bad GLOBALS\n");
  263.         exit(1);
  264.     }
  265.  
  266.     /* We're handling ACTOR and SIZE clauses here.  Note that the
  267.        grammar allows additional clauses. */
  268.  
  269.     /* prime the pump */
  270.     fgets(inbuf1, MAXBUF, fin1);
  271.     fgets(inbuf2, MAXBUF, fin2);
  272.  
  273.     /* ACTOR clauses - hard-wired to 5 lines per! */
  274.     for (;;) {
  275.         if (strncmp(inbuf1, "ACTOR", strlen("ACTOR")))
  276.             break;
  277.         fputs(inbuf1, fout);
  278.         fgets(inbuf1, MAXBUF, fin1);
  279.         fputs(inbuf1, fout);
  280.         fgets(inbuf1, MAXBUF, fin1);
  281.         fputs(inbuf1, fout);
  282.         fgets(inbuf1, MAXBUF, fin1);
  283.         fputs(inbuf1, fout);
  284.         fgets(inbuf1, MAXBUF, fin1);
  285.         fputs(inbuf1, fout);
  286.         fgets(inbuf1, MAXBUF, fin1);
  287.     }
  288.     for (;;) {
  289.         if (strncmp(inbuf2, "ACTOR", strlen("ACTOR")))
  290.             break;
  291.         /* find key string */
  292.         p = strstr(inbuf2, " FRAMES ");
  293.         if (p == NULL) {
  294.             fputs(inbuf2, fout);
  295.             continue;
  296.         }
  297.         p += strlen(" FRAMES ");
  298.         /* get start frame */
  299.         start = atoi(p);
  300.         /* write first part of line */
  301.         *p++ = '\0';
  302.         fputs(inbuf2, fout);
  303.         /* write shifted start frame */
  304.         fprintf(fout, "%d ", start + max1);
  305.         /* get end frame */
  306.         p = strchr(p, ' ');
  307.         p++;
  308.         finish = atoi(p);
  309.         /* write shifted end frame */
  310.         fprintf(fout, "%d ", finish + max1);
  311.         /* write rest of line */
  312.         p = strchr(p, ' ');
  313.         p++;
  314.         fputs(p, fout);
  315.         fgets(inbuf2, MAXBUF, fin2);
  316.         fputs(inbuf2, fout);
  317.         fgets(inbuf2, MAXBUF, fin2);
  318.         fputs(inbuf2, fout);
  319.         fgets(inbuf2, MAXBUF, fin2);
  320.         fputs(inbuf2, fout);
  321.         fgets(inbuf2, MAXBUF, fin2);
  322.         fputs(inbuf2, fout);
  323.         fgets(inbuf2, MAXBUF, fin2);
  324.     }
  325.  
  326.     /* SIZE clauses */
  327.     for (;;) {
  328.         if (strncmp(inbuf1, "SIZE", strlen("SIZE")))
  329.             break;
  330.         fputs(inbuf1, fout);
  331.         fgets(inbuf1, MAXBUF, fin1);
  332.     }
  333.     for (;;) {
  334.         if (strncmp(inbuf2, "SIZE", strlen("SIZE")))
  335.             break;
  336.         /* find key string */
  337.         p = strstr(inbuf2, " FRAMES ");
  338.         if (p == NULL) {
  339.             fputs(inbuf2, fout);
  340.             continue;
  341.         }
  342.         p += strlen(" FRAMES ");
  343.         /* get start frame */
  344.         start = atoi(p);
  345.         /* write first part of line */
  346.         *p++ = '\0';
  347.         fputs(inbuf2, fout);
  348.         /* write shifted start frame */
  349.         fprintf(fout, "%d ", start + max1);
  350.         /* get end frame */
  351.         p = strchr(p, ' ');
  352.         p++;
  353.         finish = atoi(p);
  354.         /* write shifted end frame */
  355.         fprintf(fout, "%d ", finish + max1);
  356.         /* write rest of line */
  357.         p = strchr(p, ' ');
  358.         p++;
  359.         fputs(p, fout);
  360.         fgets(inbuf2, MAXBUF, fin2);
  361.     }
  362.  
  363.     fprintf(fout, "\n");
  364.  
  365.     /* process rest of first file */
  366.     for (;;) {
  367.         /* get a line */
  368.         fgets(inbuf, MAXBUF, fin1);
  369.         if (feof(fin1))
  370.             break;
  371.         /* echo it to the output file */
  372.         fputs(inbuf, fout);
  373.     }
  374.  
  375.     /* process rest of second file */
  376.     for (;;) {
  377.         /* get a line */
  378.         fgets(inbuf, MAXBUF, fin2);
  379.         if (feof(fin2))
  380.             break;
  381.         /* find key string */
  382.         p = strstr(inbuf, " FRAMES ");
  383.         if (p == NULL) {
  384.             fputs(inbuf, fout);
  385.             continue;
  386.         }
  387.         p += strlen(" FRAMES ");
  388.         /* get start frame */
  389.         start = atoi(p);
  390.         /* write first part of line */
  391.         *p++ = '\0';
  392.         fputs(inbuf, fout);
  393.         /* write shifted start frame */
  394.         fprintf(fout, "%d ", start + max1);
  395.         /* get end frame */
  396.         p = strchr(p, ' ');
  397.         p++;
  398.         finish = atoi(p);
  399.         /* write shifted end frame */
  400.         fprintf(fout, "%d ", finish + max1);
  401.         /* write rest of line */
  402.         p = strchr(p, ' ');
  403.         p++;
  404.         fputs(p, fout);
  405.     }
  406.  
  407.     /* clean up */
  408.     fclose(fin1);
  409.     fclose(fin2);
  410.     fclose(fout);
  411. }
  412.  
  413.